<?php

namespace app\common\model;

use think\Model;


class Gameroom extends Model
{

    

    

    // 表名
    protected $name = 'game_room';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'room_type_text',
        'room_pay_type_text',
        'status_text',
        'state_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    
    public function getRoomTypeList()
    {
        return ['10' => __('Room_type 10'), '20' => __('Room_type 20'), '30' => __('Room_type 30')];
    }

    public function getRoomPayTypeList()
    {
        return ['10' => __('Room_pay_type 10'), '20' => __('Room_pay_type 20')];
    }

    public function getStatusList()
    {
        return ['100' => __('Status 100'), '101' => __('Status 101'), '102' => __('Status 102')];
    }

    public function getStateList()
    {
        return ['0' => __('State 0'), '1' => __('State 1')];
    }


    public function getRoomTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['room_type']) ? $data['room_type'] : '');
        $list = $this->getRoomTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRoomPayTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['room_pay_type']) ? $data['room_pay_type'] : '');
        $list = $this->getRoomPayTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStateTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['state']) ? $data['state'] : '');
        $list = $this->getStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function game()
    {
        return $this->belongsTo('Game', 'game_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function club()
    {
        return $this->belongsTo('app\common\model\game\Club', 'club_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
